﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STKMIS.Model;
using STKMIS.DAL;
using System.Data;

namespace STKMIS.BLL
{
    public class SaleItem
    {
        public SaleItem() { }

        public static bool InsertSaleItem(SaleItemModel saleItemInfo, DBTransaction tran, ref string msg)
        {
            int executedRows = 0;
            bool isTrue = true;
            try
            {
                List<SqlDBParameter> param = new List<SqlDBParameter>();

                param.Add(new SqlDBParameter("@SaleID", DbType.Int32, saleItemInfo.SaleID));
                param.Add(new SqlDBParameter("@ProductsAndUnitID", DbType.Int32, saleItemInfo.ProductsAndUnitID));
                param.Add(new SqlDBParameter("@SaleAmount", DbType.Decimal, saleItemInfo.SaleAmount));
                param.Add(new SqlDBParameter("@SalePrice", DbType.Decimal, saleItemInfo.SalePrice));
                param.Add(new SqlDBParameter("@SaleMoney", DbType.Decimal, saleItemInfo.SaleMoney));
                param.Add(new SqlDBParameter("@SaleProfit", DbType.Decimal, saleItemInfo.SaleProfit));

                executedRows = SqlDBServer.ExecuteStoredProc("proc_SaleItemInsert", param, tran.Transaction, SqlDBServer.SqlConnStringModelDb);

                if (executedRows <= 0)
                {
                    isTrue = false;
                }
            }
            catch (Exception)
            {
                msg = "插入失败";
                isTrue = false;
            }
            msg = "插入成功";
            return isTrue;
        }
    }
}
